﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SPSolutionFactory
{
    class APISharePoint
    {
        /// <summary>
        /// Get List do site.
        /// </summary>
        /// <param name="url">Url's site.</param>
        /// <param name="listName">Name to list.</param>
        /// <returns></returns>
        public SPList GetList(String url, String listName)
        {
            SPSite site = new SPSite(url);
            SPWeb web = site.OpenWeb();

            return web.Lists[listName];
            site.Dispose();
        }

        /// <summary>
        /// Get true if List's name exist in web. Get false if List's name non exist.
        /// </summary>
        /// <param name="web">Web's name.</param>
        /// <param name="listName">List's name.</param>
        /// <returns></returns>
        public static bool IsExistList(SPWeb web, String listName)
        {
            return web.Lists.Cast<SPList>().Any(list => String.Equals(list.Title, listName));
        }
    }
}
